import { defineStore } from "pinia";
import { ref } from 'vue'
import type { Ref } from 'vue'
interface iUser {
    loginState: boolean;
    userid: string;
    token: string;
}
export const useUserStore = defineStore('user',()=>{
    const loginState: Ref<boolean> = ref(localStorage.getItem('loginState') == 'true')
    const userid: Ref<string> = ref(localStorage.getItem('userid') || '')
    const token: Ref<string> = ref(localStorage.getItem('token') || '')
    function changeUserState(userInfo: iUser) {
        loginState.value = userInfo.loginState
        userid.value = userInfo.userid
        token.value = userInfo.token
        localStorage.setItem('loginState', String(userInfo.loginState))
        localStorage.setItem('userid', userInfo.userid)
        localStorage.setItem('token', userInfo.token)
    }
    return {
        loginState,
        userid,
        token,
        changeUserState
    }
})